Limitations of X12: the currently shipping X12 version 0.2.9 has the following limitations. First, EViews must be executed from a directory that has a proper letter drive name. If you are running EViews over the network, make sure the server directory is mapped to a letter drive on your local machine. Second, for options that require path information, there is a limitation on the path length. Specifically, X12 will not recognize long paths that have more than four subdirectories. If you encounter problems running the example files below, make sure that this restriction is satisfied (in particular watch out for the model file used for auto model selection and the "gdir=" option described below).
The directory specified by the "gdir=" option should not be the same as the working directory used by EViews since it may overwrite other saved files with the same name. You can get the working directory used by EViews by a call to the @temppath command. Make sure to set the "gdir=" path to a writeable directory.
'obtaining forecasts from x12 'revised on 3/26/2004 wfcreate x12ts4 m 1949:01 1970:4 series x x.fill 112, 118, 132, 129, 121, 135, 148, 148, 136, 119, 104, 118, 115, 126, 141, 135, 125, 149, 170, 170, 158, 133, 114, 140, 145, 150, 178, 163, 172, 178, 199, 199, 184, 162, 146, 166, 171, 180, 193, 181, 183, 218, 230, 242, 209, 191, 172, 194, 196, 196, 236, 235, 229, 243, 264, 272, 237, 211, 180, 201, 204, 188, 235, 227, 234, 264, 302, 293, 259, 229, 203, 229, 242, 233, 267, 269, 270, 315, 364, 347, 312, 274, 237, 278, 284, 277, 317, 313, 318, 374, 413, 405, 355, 306, 271, 306, 315, 301, 356, 348, 355, 422, 465, 467, 404, 347, 305, 336, 340, 318, 362, 348, 363, 435, 491, 505, 404, 359, 310, 337, 360, 342, 406, 396, 420, 472, 548, 559, 463, 407, 362, 405, 417, 391, 419, 461, 472, 535, 622, 606, 508, 461, 390, 432 '------------------------------------------------------------------------------ 'simplest method: returns forecasts only up to one year '------------------------------------------------------------------------------ smpl 1949:01 1960:12 freeze(tab1) x.x12(mode=l, arima="(0 1 1)(0 1 1)", f, flead=36, save="b1 d10 d11 d12 d13") x1 'show tab1 'split out-of-sample from in-sample series x1 = x series x1f series x1f_sf smpl 1961:01 1963:12 x1 = x1_b1 x1f = x1_b1 x1f_sf = x1_sf 'plot smpl 1960:01 1963:12 graph g1a.line x1 x1f g1a.setelem(1) legend(raw series) g1a.setelem(2) legend(forecast) graph g1b.line x1_sf x1f_sf g1b.setelem(1) legend(seasonal factors) g1b.setelem(2) legend(forecast) graph g1.merge g1a g1b g1.options size(8,2) g1.align(1,0,1.0) g1.addtext(0.1,-0.1) Simple forecasts using f option show g1 '------------------------------------------------------------------------------ 'gdir= option dumps files for graphics which has longer forecasts and confidence 'bounds (only for raw data). you need to read the data back yourself using the 'read command. look at the file evx12tmp.gmt file and Table 2-2 of the X12 manual 'for a description of each file in gdir '------------------------------------------------------------------------------ 'set paths to read output data files %gdir_path = @temppath + "\x12graphs\" smpl 1949:01 1960:12 freeze(tab2) x.x12(gdir=%gdir_path, mode=l, arima="(0 1 1)(0 1 1)", f, flead=36, save="b1 d10 d11 d12 d13") x2 'show tab2 'read forecasts from file in %gdir_path smpl 61:01 @last %filename=%gdir_path + "evx12tmp.fct" read(skiprow=2,skipcol=1) %filename x2f x2f_low x2f_upp smpl 49:01 @last %filename=%gdir_path + "evx12tmp.d10" read(skiprow=2,skipcol=1) %filename x2_sf 'split out-of-sample from in-sample smpl 1949:01 1960:12 series x2 = x series x2f_sf smpl 1961:01 1963:12 x2 = x2_b1 x2f_sf = x2_sf 'plot smpl 1960:01 1963:12 graph g2a.line x2 x2f x2f_low x2f_upp g2a.options linepat g2a.setelem(1) legend(raw series) lcolor(blue) lpat(solid) g2a.setelem(2) legend(forecast) lcolor(red) lpat(solid) g2a.setelem(3) legend(95% lower bound) linecolor(255,150,255) lpat(dash1) g2a.setelem(4) legend(95% upper bound) linecolor(255,150,255) lpat(dash1) graph g2b.line x2_sf x2f_sf g2b.setelem(1) legend(seasonal factors) g2b.setelem(2) legend(forecast) graph g2.merge g2a g2b g2.options size(8,2) g2.align(1,0,1.0) g2.addtext(0.1,-0.1) Forecasts read from gdir= files show g2
'eviews x12 interface
'replicate example 1 provided by census
'revised on 3/26/2004
'create workfile
wfcreate x12ex11 m 1967 1999
'read data
%datafile = @runpath + "s0b566.dat"
read(t,d=s,mult,norect,dropstrings) %datafile x
'estimation subsample
sample smod 1983:1 @last
'set path to dump x12 graphics metafiles
'*must set to writeable path*
%path = @temppath + "\x12graphs\"
'-----------------------------------------------------------------------
'run shoersm1.spc (x11easter adj)
'-----------------------------------------------------------------------
'set adjustment sample
smpl 1972:1 @last
'call x12
%specfile = @runpath + "ev_shoersm1.spc"
freeze(tab1) x.x12(modelsmpl=smod, ns, save="h1", gdir=%path, sfile=%specfile)
'show tab1
'read history of sum of squared forecast errors
'from evx12tmp.fce dumped in {%path}
%filename=%path + "evx12tmp.fce"
smpl 1991:2 @last
read(d=t,mult,rect,skiprow=2) %filename date x1fce01 x1fce12
'-----------------------------------------------------------------------
'run shoersm2.spc (x11easter adj)
'-----------------------------------------------------------------------
'set adjustment sample
smpl 1972:1 @last
'call x12
%specfile = @runpath + "ev_shoersm2.spc"
freeze(tab2) x.x12(modelsmpl=smod, ns, gdir=%path, sfile=%specfile)
'show tab2
'read history of sum of squared forecast errors
'from evx12tmp.fce dumped in {%path}
%filename=%path + "evx12tmp.fce"
smpl 1991:2 @last
read(d=t,mult,rect,skiprow=2) %filename date x2fce01 x2fce12
'-----------------------------------------------------------------------
'compare adjustments via difference of forecast errors
'-----------------------------------------------------------------------
series diff01 = x2fce01 - x1fce01
series diff12 = x2fce12 - x1fce12
diff01.displayname lag 1
diff12.displayname lag 12
group g1 diff01 diff12
freeze(graph1) g1.line
'add title
graph1.addtext(t) Difference of sum-of-squared forecast errors (reg_easter - x11easter)
'add zero line
graph1.draw(dashline,left) 0
show graph1
'eviews x12 interface
'replicate example 2 provided by census
'revised on 3/26/2004
'create workfile
wfcreate x12ex21 m 1964 1995
'read data
%datafile = @runpath + "x12ex2.dat"
read(t,d=s,mult,norect,dropstrings) %datafile x
'set path to dump x12 graphics metafiles
'*must set to writeable path*
%path = @temppath + "\x12graphs\"
'-----------------------------------------------------------------------
'visually check calendar month heteroskedasticity
'-----------------------------------------------------------------------
'set adjustment sample
smpl 1982:1 @last
freeze(fig1) x.seasplot
show fig1
'-----------------------------------------------------------------------
'run mw1fam0.spc (3x9 filter only)
'-----------------------------------------------------------------------
'set adjustment sample
smpl 1982:1 @last
'call x12
%specfile = @runpath + "ev_mw1fam0.spc"
freeze(tab1) x.x12(ns, gdir=%path, sfile=%specfile)
'set history sample
smpl 1992:1 @last
'read history of seasonally adjusted from evx12tmp.sae dumped in {%path}
%filename=%path + "evx12tmp.sae"
read(d=t,mult,rect,skiprow=2) %filename date x0cnc x0fin
'read history of percent change in seasonally adjusted from evx12tmp.che dumped in {%path}
%filename=%path + "evx12tmp.che"
read(d=t,mult,rect,skiprow=2) %filename date dx0cnc dx0fin
'-----------------------------------------------------------------------
'run mw1fam1.spc (3x9 and 3x5 filters)
'-----------------------------------------------------------------------
'set adjustment sample
smpl 1982:1 @last
'call x12
%specfile = @runpath + "ev_mw1fam1.spc"
freeze(tab2) x.x12(ns, gdir=%path, sfile=%specfile)
'set history sample
smpl 1992:1 @last
'read history of seasonally adjusted from evx12tmp.sae dumped in {%path}
%filename=%path + "evx12tmp.sae"
read(d=t,mult,rect,skiprow=2) %filename date x1cnc x1fin
'read history of percent change in seasonally adjusted from evx12tmp.che dumped in {%path}
%filename=%path + "evx12tmp.che"
read(d=t,mult,rect,skiprow=2) %filename date dx1cnc dx1fin
'-----------------------------------------------------------------------
'run mw1fam.spc (3x9 and 3x5 filters with calendarsigma)
'-----------------------------------------------------------------------
'set adjustment sample
smpl 1982:1 @last
'call x12
%specfile = @runpath + "ev_mw1fam.spc"
freeze(tab3) x.x12(ns, gdir=%path, sfile=%specfile)
'set history sample
smpl 1992:1 @last
'read history of seasonally adjusted from evx12tmp.sae dumped in {%path}
%filename=%path + "evx12tmp.sae"
read(d=t,mult,rect,skiprow=2) %filename date x2cnc x2fin
'read history of percent change in seasonally adjusted from evx12tmp.che dumped in {%path}
%filename=%path + "evx12tmp.che"
read(d=t,mult,rect,skiprow=2) %filename date dx2cnc dx2fin
'-----------------------------------------------------------------------
'compare revisions
'-----------------------------------------------------------------------
group g1
group g2
for !i=0 to 2
series revs{!i} = (x{!i}fin-x{!i}cnc)/x{!i}cnc
g1.add revs{!i}
series revd{!i} = (dx{!i}fin-dx{!i}cnc)/dx{!i}cnc
g2.add revd{!i}
next
freeze(gra1) g1.line
'add title
gra1.addtext(t) Revisions of seasonal adjusted values
show gra1
freeze(gra2) g2.line
'add title
gra2.addtext(t) Revisions of percent change in seasonal adjusted values
show gra2
'eviews x12 interface
'replicate example 4 provided by census
'revised on 3/26/2004
include sub_readx12spectrum.prg
'create workfile
wfcreate x12ex41 m 1979 1995
'read data
%datafile = @runpath + "m1gold.ori"
read(t,d=s,mult,norect,dropstrings) %datafile x
'set path to dump x12 graphics metafiles
'*must set to writeable path*
%path = @temppath + "\x12graphs\"
'-----------------------------------------------------------------------
'visually check seasonality
'-----------------------------------------------------------------------
'set adjustment sample
smpl 1980:1 @last
freeze(fig1) x.seasplot
show fig1
freeze(fig2) x.seasplot(m)
show fig2
'-----------------------------------------------------------------------
'run m1gold.spc
'-----------------------------------------------------------------------
'set adjustment sample
smpl 1980:1 @last
'call x12
%specfile = @runpath + "ev_m1gold.spc"
freeze(tab1) x.x12(ns, gdir=%path, sfile=%specfile)
'read seasonally adjusted series from evx12tmp.d11 dumped in {%path}
%filename=%path + "evx12tmp.d11"
read(d=t,mult,rect,skiprow=2) %filename date x_d11
'read seasonal factors from evx12tmp.d10 dumped in {%path}
%filename=%path + "evx12tmp.d10"
read(d=t,mult,rect,skiprow=2) %filename date x_d10
'plot spectrum of original series from evx12tmp.sp0 dumped in {%path}
%fname = %path + "evx12tmp.sp0"
%gname = "graph1"
call sub_readx12spectrum(%fname, %gname, 12)
{%gname}.addtext(t) Spectrum of original series
show {%gname}
'eviews x12 interface
'replicate example 5 provided by census
'last checked and revised 3/26/2004
'create workfile
wfcreate x12ex51 q 1990 1998
'fill series
series x
x.fill 97.49, 96.11, 106.17, 100.23, 91.53, 103.51, 107.44, 101.64, 95.47, 101.72, 103.71, 101.02, 98.73, 107.06, 109.16, 106.77, 103.40, 110.38, 115.79, 116.85, 114.18, 117.46, 116.99, 116.64, 112.57, 120.10, 123.26, 122.17, 116.84, 124.82, 126.79, 124.81, 118.13
'set path to dump x12 graphics metafiles
'*must set to writeable path*
%path = @temppath + "\x12graphs\"
'-----------------------------------------------------------------------
'use spec file brazgnp.spc
'-----------------------------------------------------------------------
'call x12
%specfile = @runpath + "ev_brazgnp.spc"
freeze(tab1) x.x12(ns, gdir=%path, sfile=%specfile) x1
'read seasonally adjusted series from evx12tmp.d11 dumped in {%path}
%filename= %path+ "evx12tmp.d11"
read(d=t,mult,rect,skiprow=2) %filename date x1_sa
'read seasonal factors from evx12tmp.d10 dumped in {%path}
%filename= %path+ "evx12tmp.d10"
read(d=t,mult,rect,skiprow=2) %filename date x1_sf
'-----------------------------------------------------------------------
'replicate brazgnp.spc
'-----------------------------------------------------------------------
'call x12 without external spec file
freeze(tab2) x.x12(gdir=%path, save="d10 d11", reg="ao1990.2 tdnolpyear", arima="(0 1 1)(0 1 1)", check, mode=a, flead=4) x2
'should all be zeros
show x1_sa-x2_sa x1_sf-x2_sf
'eviews x12 interface 'replicate example 6 provided by census 'revised on 3/26/2004 'create workfile wfcreate x12ex61 m 1986 1996 'read series %datafile = @runpath + "index.dat" read(norect,dropstrings) %datafile x 'set path to dump x12 graphics metafiles '*must set to writeable path* %path = @temppath + "\x12graphs\" '----------------------------------------------------------------------- 'replicate index0.spc (full sample estimation) '----------------------------------------------------------------------- 'call x12 without external spec file freeze(tab0) x.x12(gdir=%path, save="d10", reg="ao1990.4", arima="([1,6] 1 0)(0 1 1)", check, tf=0, flead=36) x0 '----------------------------------------------------------------------- 'replicate index.spc (subsample estimation) '----------------------------------------------------------------------- 'call x12 without external spec file freeze(tab1) x.x12(gdir=%path, save="d10 d11", reg="ao1990.4", arima="([1,6] 1 0)(0 1 1)", check, tf=0, flead=36, modelsmpl="1989.1 @last") x1
'eviews x12 interface
'replicate example 7 provided by census
'last checked and revised 3/29/2004
include sub_readx12spectrum.prg
'create workfile
wfcreate x12ex71 m 1980 1996
'read series
%datafile = @runpath + "cetgengq.dat"
read(norect,dropstrings) %datafile x
'set path to dump x12 graphics metafiles
'*must set to writeable path*
%path = @temppath + "\x12graphs\"
'-----------------------------------------------------------------------
'default run (full sample)
'-----------------------------------------------------------------------
'call x12 without external spec file
freeze(tab0) x.x12(gdir=%path, save="d10", check, tf=0, flead=24, outlier, plotspectra, amdl=f) x0
'make copy of diagnostic spetra (will be overwritten)
copy gr_x0_sp gr0spe
show gr0spe
'plot regARIMA resid spectrum
%fname = %path + "EVX12TMP.spr"
%gname = "g0res"
!freq = 12
call sub_readX12Spectrum(%fname, %gname, !freq)
{%gname}.addtext(t) Spectrum of regARIMA residuals (full sample)
show {%gname}
'-----------------------------------------------------------------------
'default run (subsample as in cetg0.spc)
'-----------------------------------------------------------------------
smpl 1986:1 @last
'call x12 without external spec file
freeze(tab1) x.x12(gdir=%path, save="d10", check, tf=0, flead=24, outlier, plotspectra, amdl=f) x1
'make copy of diagnostic spetra (will be overwritten)
copy gr_x1_sp gr1spe
show gr1spe
'plot regARIMA resid spectrum
%fname = %path + "EVX12TMP.spr"
%gname = "g1res"
!freq = 12
call sub_readX12Spectrum(%fname, %gname, !freq)
{%gname}.addtext(t) Spectrum of regARIMA residuals (subsample)
show {%gname}
'eviews x12 interface
'replicate example 7 provided by census
'last checked and revised 3/26/2004
'create workfile
wfcreate x12ex72 m 1980 1996
'read series
%datafile = @runpath + "s0b566.dat"
read(norect,dropstrings) %datafile x
'set path to dump x12 graphics metafiles
'*must set to writeable path*
%gpath = @temppath + "\x12graphs\"
'-----------------------------------------------------------------------
'compare various trading day correction methods
'-----------------------------------------------------------------------
!i=0
for %sfile ev_cetg0.spc ev_cetg1.spc ev_cetg2.spc ev_cetg3.spc ev_cetgengq.spc
statusline running spec !i...
smpl 1986:1 @last
'call x12 with external spec file
%sname = @runpath + %sfile
freeze(tab{!i}) x.x12(ns, gdir=%gpath, sfile=%sname) x{!i}
'read history of sum of squared forecast errors from evx12tmp.fce dumped in {%gpath}
smpl 1992:2 @last
%filename= %gpath+"evx12tmp.fce"
read(d=t,mult,rect,skiprow=2) %filename date x{!i}fce01 x{!i}fce12
'read history of logl and AIC from evx12tmp.lkh dumped in {%gpath}
smpl 1992:1 @last
%filename=%gpath + "evx12tmp.lkh"
read(d=t,mult,rect,skiprow=2) %filename date x{!i}logl x{!i}aic
'increment index number
!i = !i + 1
next
'-----------------------------------------------------------------------
'plot history of forecast errors from various trading day correction methods
'-----------------------------------------------------------------------
group g01
group g12
for !i=0 to 4
g01.add x{!i}fce01
g12.add x{!i}fce12
next
freeze(gra01) g01.line
freeze(gra12) g12.line
'change graph labels
for %name 01 12
gra{%name}.element(1) legend(none)
gra{%name}.element(2) legend(tdstock)
gra{%name}.element(3) legend(td)
gra{%name}.element(4) legend(td1coef)
gra{%name}.element(5) legend(census final)
gra{%name}.element(5) symbol(circle)
gra{%name}.legend columns(1) position(right)
gra{%name}.addtext(t) Sum of squared forecast errors (lag {%name})
next
'gra01.addtext(t) Sum of squared forecast errors (lag 1)
'gra12.addtext(t) Sum of squared forecast errors (lag 12)
show gra01
show gra12
'eviews x12 interface 'replicate example 8 provided by census 'warning: data file path hard-coded in .spc files 'last checked and revised 3/29/2004 'create workfile wfcreate x12ex81 m 1972 1989 'read series %datafile = @runpath + "s0b566.dat" read(norect,dropstrings) %datafile x 'set path to dump x12 graphics metafiles '*must set to writeable path* %path = @temppath + "\x12graphs\" '----------------------------------------------------------------------- 'no preadjustment in transform '----------------------------------------------------------------------- 'call x12 with external spec file smpl @all %specfile = @runpath + "ev_beauto0.spc" freeze(tab0) x.x12(gdir=%path, ns, sfile=%specfile) x0 'read history of logl and AIC from evx12tmp.lkh dumped in %gpath smpl 1979:1 @last %filename = %path+"evx12tmp.lkh" read(d=t,mult,rect,skiprow=2) %filename date x0logl x0aic '----------------------------------------------------------------------- 'with preadjustment in transform '----------------------------------------------------------------------- 'read subjective adjustment factors smpl @all %datafile = @runpath + "beauto.adj" read(norect,dropstrings) %datafile xadj 'display subjective factors xadj.displayname subjective factors (hybrid?) freeze(gra_adj) xadj.line show gra_adj 'call x12 with external spec file smpl @all %specfile = @runpath + "ev_beauto.spc" freeze(tab1) x.x12(gdir=%path, ns, sfile=%specfile) x1 'read history of logl and AIC from evx12tmp.lkh dumped in %gpath smpl 1979:1 @last %filename=%path + "evx12tmp.lkh" read(d=t,mult,rect,skiprow=2) %filename date x1logl x1aic '----------------------------------------------------------------------- 'compare effect of preadjustment '----------------------------------------------------------------------- 'AIC difference series adiff = x0aic - x1aic adiff.displayname no_adj_aic - adj_aic freeze(gra2) adiff.line gra2.addtext(t) History of AIC difference show gra2 series ldiff = x0logl - x1logl ldiff.displayname no_adj_logl - adj_logl freeze(gra3) ldiff.line gra3.addtext(t) History of logl difference show gra3
'eviews x12 interface
'replicate example 9 provided by census
'trend extraction of seasonally adjusted series
'revised on 3/26/2004
'create workfile
wfcreate x12ex91 m 1981 1997
'read series
%datafile = @runpath + "usstrts2.dat"
read(norect,dropstrings) %datafile x
'precision=1
x = x/10
'set path to dump x12 graphics metafiles
'*must set to writeable path*
%path = @temppath + "\x12graphs\"
'-----------------------------------------------------------------------
'seasonal adjustment and trend
'-----------------------------------------------------------------------
'call x12
smpl 84:3 @last
%specfile = @runpath + "ev_strtsnsd0.spc"
freeze(tab0) x.x12(gdir=%path, ns, sfile=%specfile) x0
'read trend-cycle from evx12tmp.d12 dumped in {%path}
%filename=%path + "evx12tmp.d12"
read(d=t,mult,rect,skiprow=2) %filename date x0d12
'-----------------------------------------------------------------------
'only trend
'-----------------------------------------------------------------------
smpl 84:3 @last
%specfile = @runpath + "ev_strtsnsd.spc"
freeze(tab1) x.x12(gdir=%path, ns, sfile=%specfile) x1
'read trend-cycle from evx12tmp.d12 dumped in {%path}
%filename=%path + "evx12tmp.d12"
read(d=t,mult,rect,skiprow=2) %filename date x1d12
'-----------------------------------------------------------------------
'display difference
'-----------------------------------------------------------------------
series tcdiff = x0d12 - x1d12
tcdiff.displayname adj_trend - no_adj_trend
freeze(gra1) tcdiff.line
show gra1